const wechatSerivce = think.service('wechat'),
	tokenService = think.service('token');

module.exports = class extends think.Controller {
	async __before() {
		let ctrl = this.ctx.controller,
			atn = this.ctx.action;

		if (ctrl === 'auth' && atn === 'login' || ctrl == 'websocket') {
			console.log('login')
		} else {
			let receivedToken = this.header('token'),
				tokenResult = await tokenService.verifyToken(receivedToken);
			if(!receivedToken){
				return this.fail('无效token');
				// return false;
			}
			if (tokenResult.error) {
				return this.fail(tokenResult.msg);
				// return false;
			}else {
				this.ctx.state.openid = tokenResult.data.id;
				console.log('>> 当前openid <<',this.ctx.state.openid)
			}
		}
	}

};
